﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using TSL.BLL;
using TSL.Model;

namespace TSL.AjaxResult
{
    public class Publich
    {
        [TSL.Utility.jQueryInvokeMethod()]
        public OpenCodeResult GetOpenCodeInfo(string ssc_id)
        {
            int ssc_idInt = -1;
            try
            {
                ssc_idInt = int.Parse(ssc_id);
            }
            catch
            {
                return new OpenCodeResult(-999, "非法入侵本次将会记录！");
            }

            GetOpenCodeBuySSCID table = new TSL.BLL.GetOpenCodes().GetModelBySSCID(ssc_idInt.ToString());

            if (table == null)
            {
                return new OpenCodeResult(-2, "无数据！");
            }

            OpenCodeResult openres = new OpenCodeResult();
            openres.Table = table;
            return openres;
        }

        [TSL.Utility.jQueryInvokeMethod()]
        public OpenCodeHisResult GetListSSCHis(string ssc_id)
        {
            int ssc_idInt = -1;
            try
            {
                ssc_idInt = int.Parse(ssc_id);
            }
            catch
            {
                return new OpenCodeHisResult(-999, "非法入侵本次将会记录！");
            }

            DataTable table = new TSL.BLL.GetOpenCodes().GetListGetHis("ssc_id=" + ssc_idInt.ToString()).Tables[0];

            if (table.Rows.Count == 0)
            {
                return new OpenCodeHisResult(-2, "无数据！");
            }

            OpenCodeHisResult openres = new OpenCodeHisResult();
            openres.Table = table;
            return openres;
        }

        [TSL.Utility.jQueryInvokeMethod()]
        public NoticeResult GetNoticeList()
        {
            DataTable table = new TSL.BLL.Notice().GetNotice("").Tables[0];

            if (table.Rows.Count == 0)
            {
                return new NoticeResult(-2, "无数据！");
            }

            NoticeResult openres = new NoticeResult();
            openres.Table = table;
            return openres;
        }

        [TSL.Utility.jQueryInvokeMethod()]
        public GradeBonusResult GetGradeBonus(string ssc_id)
        {
            int ssc_idInt = -1;
            try
            {
                ssc_idInt = int.Parse(ssc_id);
            }
            catch
            {
                return new GradeBonusResult(-999, "非法入侵本次将会记录！");
            }

            DataTable table = new TSL.BLL.GetNaviagetion().GetGradeBonus("id=" + ssc_idInt.ToString() + " and state=100").Tables[0];
            if (table.Rows.Count == 0)
            {
                return new GradeBonusResult(-2, "无数据！");
            }

            GradeBonusResult openres = new GradeBonusResult();
            openres.Table = table;
            return openres;
        }


        [TSL.Utility.jQueryInvokeMethod()]
        public GradeBonusResult GetNaviagetion(string ssc_id, int classid)
        {
            int ssc_idInt = -1;
            try
            {
                ssc_idInt = int.Parse(ssc_id);
            }
            catch
            {
                return new GradeBonusResult(-999, "非法入侵本次将会记录！");
            }

            DataTable table = new TSL.BLL.GetNaviagetion().GetListFromView(string.Concat(new object[] { " caipiao_id=", ssc_id.ToString(), " and GradeBonus=", classid.ToString(), " and state=100" })).Tables[0];
            if (table.Rows.Count == 0)
            {
                return new GradeBonusResult(-2, "无数据！");
            }

            GradeBonusResult openres = new GradeBonusResult();
            openres.Table = table;
            return openres;
        }

        [TSL.Utility.jQueryInvokeMethod()]
        public WinnerResult GetWinnerResult(string ssc_id)
        {
            int ssc_idInt = -1;
            try
            {
                ssc_idInt = int.Parse(ssc_id);
            }
            catch
            {
                return new WinnerResult(-999, "非法入侵本次将会记录！");
            }

            string sql = string.Format(" sscid={0} ", ssc_idInt.ToString());
            string parmer = " id,ssc_name,sscid,caipiao_name,username,wincost ";

            DataTable table = new TSL.BLL.GetOpenCodes().GetWinnerList(parmer, sql).Tables[0];
            if (table.Rows.Count == 0)
            {
                return new WinnerResult(-2, "无数据！");
            }

            WinnerResult openres = new WinnerResult();
            openres.Table = table;
            return openres;
        }

        [TSL.Utility.jQueryInvokeMethod()]
        public WinnerResult GetWinnerInfoResult(string ssc_id, string buy_id)
        {
            int ssc_idInt = -1;
            int buy_idInt = -1;
            try
            {
                ssc_idInt = int.Parse(ssc_id);
                buy_idInt = int.Parse(buy_id);
            }
            catch
            {
                return new WinnerResult(-999, "非法入侵本次将会记录！");
            }

            string sql = string.Format(" sscid={0} and id={1} ", ssc_idInt.ToString(), buy_idInt.ToString());
            DataTable table = new TSL.BLL.GetOpenCodes().GetWinner(sql).Tables[0];
            if (table.Rows.Count == 0)
            {
                return new WinnerResult(-2, "无数据！");
            }

            WinnerResult openres = new WinnerResult();
            openres.Table = table;
            return openres;

        }

        [TSL.Utility.jQueryInvokeMethod()]
        public BetMenuResult GetBetMenuResult(string bet_id)
        {
            int bet_idInt = -1;
            try
            {
                bet_idInt = int.Parse(bet_id);
            }
            catch
            {
                return new BetMenuResult(-999, "非法入侵本次将会记录！");
            }

            SYS_BetMenu betmenu = new TSL.BLL.BetMenu().GetModel(bet_idInt.ToString());
            if (betmenu==null)
            {
                return new BetMenuResult(-2, "无数据！");
            }

            BetMenuResult openres = new BetMenuResult();
            openres.BetMenu = double.Parse(betmenu.BetMenu);
            openres.Factor = betmenu.Factor;
            return openres;
        }

        [TSL.Utility.jQueryInvokeMethod()]
        public SSCInforResult GetSSCInfor(string ssc_id)
        {
            int ssc_idInt = -1;
            try
            {
                ssc_idInt = int.Parse(ssc_id);
            }
            catch
            {
                return new SSCInforResult(-999, "非法入侵本次将会记录！");
            }

            DataTable table = new TSL.BLL.GetNaviagetion().GetCaiPiao("propertys='彩票' and state='正常' and id=" + ssc_idInt.ToString() + "").Tables[0];
            if (table.Rows.Count == 0)
            {
                return new SSCInforResult(-2, "无数据！");
            }

            SSCInforResult openres = new SSCInforResult();
            openres.SSCName = table.Rows[0]["sscname"].ToString();
            openres.WeiShu = int.Parse(table.Rows[0]["weishu"].ToString());
            return openres;
        }
    }
}
